<template>
    <div class="password">
        <div class="verify">
            <p class="bor_box">
                <img src="../../assets/images/login/per.png">
                <van-field 
                    v-model="email" 
                    placeholder="请输入邮箱账号" 
                />
            </p>
            <p class="verification bor_box">
                <img src="../../assets/images/login/passw.png">
                <van-field
                    v-model="password"
                    :type="type"
                    placeholder="请输入密码"
                />
                <img v-if="isOpen" src="../../assets/images/login/eyeOpen.png" @click="ChangeEye">
                <img v-if="!isOpen" src="../../assets/images/login/eyeClose.png" @click="ChangeEye">
            </p>
        </div>
        <p class="register">没有账号请先 <span @click="register">立即注册</span></p>
        <p class="btn" @click="immediately">登录</p>
        <p class="third-title">第三方登录</p>
        <div class="third-party">
            <!-- <img @click="thirdLogin('WEICHAT_AUTH')" src="../../assets/images/wx.png"> -->
            <img @click="thirdLogin('ALI_AUTH')" src="../../assets/images/zfb.png">
        </div>
    </div>
</template>
<script>
document.querySelector('#test').addEventListener('click', function() {
  ap.getAuthCode({
    appId: '${appId}',
    scopes: ['auth_user'],
  }, function(res){
    ap.alert(JSON.stringify(res));
  });
});
</script>
<script>
import { doLogin,preLogin } from "../../api/user.js";
export default {
    name:'password',
    data(){
        return{
            email:"",
            password:"",
            isOpen:false,
            type:"password"
        }
    },
    methods:{
        ChangeEye(){
            this.isOpen = !this.isOpen
            if(this.isOpen){
                this.type = "text"
            }else{
                this.type = "password"
            }
        },
        register(){
            this.$router.push({ name: "register" });
        },
        immediately(){
            if(this.email==""){
                this.$toast('请输入账号');
                return
            };
            if(this.password==""){
                this.$toast('请输入密码');
                return
            };
            doLogin({
                "loginNo": this.email,
                "loginPass": this.password,
            }).then(response=>{
                if(response.retCode=="200"){
                    let obj = {
                        token:response.data,
                        user:this.email
                    }
                    localStorage.setItem("userInfo",JSON.stringify(obj));
                    this.$router.push({ name: "" });
                }else{
                    this.$toast(response.retMsg);
                }
                
            });
        },
        thirdLogin(type){
            preLogin({
                "authTypeEnum": type,
                "webSourceEnum": "H5_WEB",
            }).then(response=>{
                window.location.href = "alipays://platformapi/startapp?appId=20000067&url="+response.data
            });
        }
    }
}
</script>

<style lang="less" scoped> 
.van-cell{
    width: 80%;
}
.third-title{
    font-size: .13rem;
    color: #9e9e9e;
    margin-top: .1rem;
    margin-left: .2rem;
}
.third-party{
    display: flex;
    justify-content: start;
    margin-top: .15rem;
    img{
        width: .5rem;
        height: .5rem;
        margin-left: .2rem;
    }
}
.verify {
  padding: 0 .2rem;
  img{
    width: .22rem;
    height: .22rem;
    margin-right:.1rem;
  }
  .bor_box{
    border: 1px solid #ededed;
    display: flex;
    justify-content: flex-start;
    border-radius: .45rem;
    align-items: center;
    padding-left: .3rem;
  }
  .verification {
    position: relative;
    margin-top: 0.2rem;
    span {
      position: absolute;
      top: (5/75) + rem;
      right: -(10/75) + rem;
      display: block;
      width: 3rem;
      font-size: 0.35rem;
      color: #F83106 ;
      line-height: 1.2rem;
      text-align: center;
    }
  }
}
.register{
    font-size: .14rem;
    color: #afadad;
    text-align: right;
    padding: .2rem .2rem 0 0;
    span{
        color: #F83106;
        text-decoration: underline;
    }
}
.btn {
  line-height: .45rem;
  background: #F83106;
  font-size: 0.16rem;
  color: #fff;
  text-align: center;
  margin-top: 0.5rem;
  border-radius: .3rem;
}
</style>
